
#include "ImageEntity.h"

#include <SDL2/SDL_opengl.h>
#include <ALittleClient/LogSystem/LogSystem.h>

namespace ALittle
{

ImageEntity::ImageEntity()
:m_texture_id(0)
, m_tex_top(0), m_tex_bottom(1), m_tex_left(0), m_tex_right(1)
, m_red(1), m_green(1), m_blue(1), m_alpha(1)
{ }

ImageEntity::~ImageEntity()
{
}

void ImageEntity::Draw()
{
	if (!m_texture_id) return;

	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, m_texture_id);
	glBegin(GL_QUADS);
		glColor4f(m_red, m_green, m_blue, m_alpha);
		glTexCoord2f(m_tex_left,	m_tex_bottom);	glVertex3f(-0.5f, -0.5f, 0.0f);
		glTexCoord2f(m_tex_right,	m_tex_bottom);	glVertex3f(0.5f, -0.5f, 0.0f);
		glTexCoord2f(m_tex_right,	m_tex_top);		glVertex3f(0.5f, 0.5f, 0.0f);
		glTexCoord2f(m_tex_left,	m_tex_top);		glVertex3f(-0.5f, 0.5f, 0.0f);
	glEnd();
	glDisable(GL_TEXTURE_2D);
}

void ImageEntity::SetRed(float red)
{
	m_red = red;
}
void ImageEntity::SetGreen(float green)
{
	m_green = green;
}
void ImageEntity::SetBlue(float blue)
{
	m_blue = blue;
}

void ImageEntity::SetAlpha(float  alpha)
{
	m_alpha = alpha;
}

void ImageEntity::SetTexture(GLuint texture_id)
{
	m_texture_id = texture_id;
}

void ImageEntity::SetTextureCoord(float top, float bottom, float left, float right)
{
	m_tex_top = top;
	m_tex_bottom = bottom;
	m_tex_left = left;
	m_tex_right = right;
}

} // ALittle
